package org.cskj.demo.controller;

import org.cskj.demo.pojo.Shop;
import org.cskj.demo.pojo.Shoptype;
import org.cskj.demo.service.imp.ShopTypeImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@ResponseBody
@RequestMapping("/shoptype")
public class ShopTypeCon {
    @Autowired
    private ShopTypeImp shopTypeImp;
   @RequestMapping("/all")
    public List<Shoptype> getall(){
       List<Shoptype> list = shopTypeImp.selectAll();
       return list;
   }
   @RequestMapping("/insert")
   public String insert(Shoptype shoptype){
       boolean check1=shopTypeImp.checkname(shoptype.getShoptypename());
       if(check1){
           int i=shopTypeImp.insert(shoptype);
           if(i>0){
               return "ok";
           }else {
               return "error";
           }
       }else {
           return "s";
       }
   }
   @RequestMapping("/update")
   public String update(Shoptype shoptype){
       int update = shopTypeImp.update(shoptype);
       if (update>0){
           return "ok";
       }else {
           return "error";
       }
   }
    @RequestMapping("/check")
    public Shoptype check(String shoptypename){
        List<Shoptype> list = shopTypeImp.check(shoptypename);
        if (list.size()==0){
            System.out.println("----");
            return new Shoptype();
        }else {
            return list.get(0);
        }
    }
   @RequestMapping("/checkname")
   public String checkname(String shoptypename){
       boolean checkname = shopTypeImp.checkname(shoptypename);
       if (checkname){
           return "ok";
       }else {
           return "error";
       }
   }
    @RequestMapping("/delete")
    public String delete(int shoptypeid){
        System.out.println(shoptypeid);
        int delete = shopTypeImp.delete(shoptypeid);

        if (delete>0){
            return "ok";
        }else {
            return "error";
        }
    }

}
